package com.katydid.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;

/**
 * Entity implementation class for Entity: Category
 *
 */
@Entity
@NamedQueries({
    @NamedQuery(name = Category.FIND_ALL, query = "SELECT c FROM Category c"),
    @NamedQuery(name = Category.FIND_BY_NAME, query = "SELECT c from Category c where c.name=:cname")
})
public class Category implements Serializable {
	
	public static final String FIND_ALL = "Category.findAll";
	public static final String FIND_BY_NAME = "Category.findByName";
	
	@Id
	@Column(name = "category_id")
	@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seq_gen")
	private long id;
	
	private String name;
	
	private String directory;
	
	@OneToMany(cascade = CascadeType.ALL, mappedBy = "category")
	private List<Tag> tags = new ArrayList<Tag>();

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDirectory() {
		return directory;
	}

	public void setDirectory(String directory) {
		this.directory = directory;
	}

	public List<Tag> getTags() {
		return tags;
	}

	public void setTags(List<Tag> tags) {
		this.tags = tags;
	}
	
	public void addTag(Tag tag) {
		getTags().add(tag);
		tag.setCategory(this);
	}
  
}
